import request from './index'

// API通用响应接口
export interface ApiResponse<T = any> {
  code: number
  message: string
  data: T
}

// 登录请求参数
export interface LoginParams {
  username: string
  password: string
}

// 登录响应
export interface LoginResult {
  token: string
  username: string
  avatar: string
  roles: string[]
}

// 用户信息
export interface UserInfo {
  id: string
  username: string
  avatar?: string
  roles: string[]
  permissions: string[]
}

/**
 * 用户登录
 */
export function login(data: LoginParams): Promise<ApiResponse<LoginResult>> {
  return request({
    url: '/api/user/login',
    method: 'post',
    data
  })
}

/**
 * 获取用户信息
 */
export function getUserInfo(): Promise<ApiResponse<UserInfo>> {
  return request({
    url: '/api/user/info',
    method: 'get'
  })
}

/**
 * 退出登录
 */
export function logout(): Promise<ApiResponse<null>> {
  return request({
    url: '/api/user/logout',
    method: 'post'
  })
} 